import 'package:distribution_mall_flutter/generated/json/base/json_convert_content.dart';
import 'package:distribution_mall_flutter/entity/goods/list/goods_list_entity.dart';

GoodsListEntity $GoodsListEntityFromJson(Map<String, dynamic> json) {
  final GoodsListEntity goodsListEntity = GoodsListEntity();
  final PageResult? pageResult = jsonConvert.convert<PageResult>(
      json['pageResult']);
  if (pageResult != null) {
    goodsListEntity.pageResult = pageResult;
  }
  final List<
      dynamic>? imageSearchCustomCodes = (json['imageSearchCustomCodes'] as List<
      dynamic>?)?.map(
          (e) => e).toList();
  if (imageSearchCustomCodes != null) {
    goodsListEntity.imageSearchCustomCodes = imageSearchCustomCodes;
  }
  final String? searchId = jsonConvert.convert<String>(json['searchId']);
  if (searchId != null) {
    goodsListEntity.searchId = searchId;
  }
  return goodsListEntity;
}

Map<String, dynamic> $GoodsListEntityToJson(GoodsListEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['pageResult'] = entity.pageResult?.toJson();
  data['imageSearchCustomCodes'] = entity.imageSearchCustomCodes;
  data['searchId'] = entity.searchId;
  return data;
}

extension GoodsListEntityExtension on GoodsListEntity {
  GoodsListEntity copyWith({
    PageResult? pageResult,
    List<dynamic>? imageSearchCustomCodes,
    String? searchId,
  }) {
    return GoodsListEntity()
      ..pageResult = pageResult ?? this.pageResult
      ..imageSearchCustomCodes = imageSearchCustomCodes ??
          this.imageSearchCustomCodes
      ..searchId = searchId ?? this.searchId;
  }
}

PageResult $PageResultFromJson(Map<String, dynamic> json) {
  final PageResult pageResult = PageResult();
  final GoodsPageMeta? goodsPageMeta = jsonConvert.convert<GoodsPageMeta>(
      json['goodsPageMeta']);
  if (goodsPageMeta != null) {
    pageResult.goodsPageMeta = goodsPageMeta;
  }
  final List<Item>? items = (json['items'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<Item>(e) as Item).toList();
  if (items != null) {
    pageResult.items = items;
  }
  return pageResult;
}

Map<String, dynamic> $PageResultToJson(PageResult entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['goodsPageMeta'] = entity.goodsPageMeta?.toJson();
  data['items'] = entity.items?.map((v) => v.toJson()).toList();
  return data;
}

extension PageResultExtension on PageResult {
  PageResult copyWith({
    GoodsPageMeta? goodsPageMeta,
    List<Item>? items,
  }) {
    return PageResult()
      ..goodsPageMeta = goodsPageMeta ?? this.goodsPageMeta
      ..items = items ?? this.items;
  }
}

Item $ItemFromJson(Map<String, dynamic> json) {
  final Item item = Item();
  final String? saleUnitId = jsonConvert.convert<String>(json['saleUnitId']);
  if (saleUnitId != null) {
    item.saleUnitId = saleUnitId;
  }
  final bool? sample = jsonConvert.convert<bool>(json['sample']);
  if (sample != null) {
    item.sample = sample;
  }
  final String? customCode = jsonConvert.convert<String>(json['customCode']);
  if (customCode != null) {
    item.customCode = customCode;
  }
  final String? title = jsonConvert.convert<String>(json['title']);
  if (title != null) {
    item.title = title;
  }
  final ImageInfo? imageInfo = jsonConvert.convert<ImageInfo>(
      json['imageInfo']);
  if (imageInfo != null) {
    item.imageInfo = imageInfo;
  }
  final BrandInfo? brandInfo = jsonConvert.convert<BrandInfo>(
      json['brandInfo']);
  if (brandInfo != null) {
    item.brandInfo = brandInfo;
  }
  final CategoryInfo? categoryInfo = jsonConvert.convert<CategoryInfo>(
      json['categoryInfo']);
  if (categoryInfo != null) {
    item.categoryInfo = categoryInfo;
  }
  final PriceInfo? priceInfo = jsonConvert.convert<PriceInfo>(
      json['priceInfo']);
  if (priceInfo != null) {
    item.priceInfo = priceInfo;
  }
  final String? refSaleItemId = jsonConvert.convert<String>(
      json['refSaleItemId']);
  if (refSaleItemId != null) {
    item.refSaleItemId = refSaleItemId;
  }
  final int? moq = jsonConvert.convert<int>(json['moq']);
  if (moq != null) {
    item.moq = moq;
  }
  final int? maxMoq = jsonConvert.convert<int>(json['maxMoq']);
  if (maxMoq != null) {
    item.maxMoq = maxMoq;
  }
  final String? locale = jsonConvert.convert<String>(json['locale']);
  if (locale != null) {
    item.locale = locale;
  }
  final bool? isLocalShipping = jsonConvert.convert<bool>(
      json['isLocalShipping']);
  if (isLocalShipping != null) {
    item.isLocalShipping = isLocalShipping;
  }
  final String? shipsFrom = jsonConvert.convert<String>(json['shipsFrom']);
  if (shipsFrom != null) {
    item.shipsFrom = shipsFrom;
  }
  return item;
}

Map<String, dynamic> $ItemToJson(Item entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['saleUnitId'] = entity.saleUnitId;
  data['sample'] = entity.sample;
  data['customCode'] = entity.customCode;
  data['title'] = entity.title;
  data['imageInfo'] = entity.imageInfo?.toJson();
  data['brandInfo'] = entity.brandInfo?.toJson();
  data['categoryInfo'] = entity.categoryInfo?.toJson();
  data['priceInfo'] = entity.priceInfo?.toJson();
  data['refSaleItemId'] = entity.refSaleItemId;
  data['moq'] = entity.moq;
  data['maxMoq'] = entity.maxMoq;
  data['locale'] = entity.locale;
  data['isLocalShipping'] = entity.isLocalShipping;
  data['shipsFrom'] = entity.shipsFrom;
  return data;
}

extension ItemExtension on Item {
  Item copyWith({
    String? saleUnitId,
    bool? sample,
    String? customCode,
    String? title,
    ImageInfo? imageInfo,
    BrandInfo? brandInfo,
    CategoryInfo? categoryInfo,
    PriceInfo? priceInfo,
    String? refSaleItemId,
    int? moq,
    int? maxMoq,
    String? locale,
    bool? isLocalShipping,
    String? shipsFrom,
  }) {
    return Item()
      ..saleUnitId = saleUnitId ?? this.saleUnitId
      ..sample = sample ?? this.sample
      ..customCode = customCode ?? this.customCode
      ..title = title ?? this.title
      ..imageInfo = imageInfo ?? this.imageInfo
      ..brandInfo = brandInfo ?? this.brandInfo
      ..categoryInfo = categoryInfo ?? this.categoryInfo
      ..priceInfo = priceInfo ?? this.priceInfo
      ..refSaleItemId = refSaleItemId ?? this.refSaleItemId
      ..moq = moq ?? this.moq
      ..maxMoq = maxMoq ?? this.maxMoq
      ..locale = locale ?? this.locale
      ..isLocalShipping = isLocalShipping ?? this.isLocalShipping
      ..shipsFrom = shipsFrom ?? this.shipsFrom;
  }
}

BrandInfo $BrandInfoFromJson(Map<String, dynamic> json) {
  final BrandInfo brandInfo = BrandInfo();
  final String? brandId = jsonConvert.convert<String>(json['brandId']);
  if (brandId != null) {
    brandInfo.brandId = brandId;
  }
  final String? brandName = jsonConvert.convert<String>(json['brandName']);
  if (brandName != null) {
    brandInfo.brandName = brandName;
  }
  return brandInfo;
}

Map<String, dynamic> $BrandInfoToJson(BrandInfo entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['brandId'] = entity.brandId;
  data['brandName'] = entity.brandName;
  return data;
}

extension BrandInfoExtension on BrandInfo {
  BrandInfo copyWith({
    String? brandId,
    String? brandName,
  }) {
    return BrandInfo()
      ..brandId = brandId ?? this.brandId
      ..brandName = brandName ?? this.brandName;
  }
}

CategoryInfo $CategoryInfoFromJson(Map<String, dynamic> json) {
  final CategoryInfo categoryInfo = CategoryInfo();
  final String? categoryId = jsonConvert.convert<String>(json['categoryId']);
  if (categoryId != null) {
    categoryInfo.categoryId = categoryId;
  }
  final String? categoryName = jsonConvert.convert<String>(
      json['categoryName']);
  if (categoryName != null) {
    categoryInfo.categoryName = categoryName;
  }
  return categoryInfo;
}

Map<String, dynamic> $CategoryInfoToJson(CategoryInfo entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['categoryId'] = entity.categoryId;
  data['categoryName'] = entity.categoryName;
  return data;
}

extension CategoryInfoExtension on CategoryInfo {
  CategoryInfo copyWith({
    String? categoryId,
    String? categoryName,
  }) {
    return CategoryInfo()
      ..categoryId = categoryId ?? this.categoryId
      ..categoryName = categoryName ?? this.categoryName;
  }
}

ImageInfo $ImageInfoFromJson(Map<String, dynamic> json) {
  final ImageInfo imageInfo = ImageInfo();
  final String? imageUrl = jsonConvert.convert<String>(json['imageUrl']);
  if (imageUrl != null) {
    imageInfo.imageUrl = imageUrl;
  }
  return imageInfo;
}

Map<String, dynamic> $ImageInfoToJson(ImageInfo entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['imageUrl'] = entity.imageUrl;
  return data;
}

extension ImageInfoExtension on ImageInfo {
  ImageInfo copyWith({
    String? imageUrl,
  }) {
    return ImageInfo()
      ..imageUrl = imageUrl ?? this.imageUrl;
  }
}

PriceInfo $PriceInfoFromJson(Map<String, dynamic> json) {
  final PriceInfo priceInfo = PriceInfo();
  final double? minSalePrice = jsonConvert.convert<double>(
      json['minSalePrice']);
  if (minSalePrice != null) {
    priceInfo.minSalePrice = minSalePrice;
  }
  final double? maxSalePrice = jsonConvert.convert<double>(
      json['maxSalePrice']);
  if (maxSalePrice != null) {
    priceInfo.maxSalePrice = maxSalePrice;
  }
  final double? maxSuggestedRetailPrice = jsonConvert.convert<double>(
      json['maxSuggestedRetailPrice']);
  if (maxSuggestedRetailPrice != null) {
    priceInfo.maxSuggestedRetailPrice = maxSuggestedRetailPrice;
  }
  final double? minSuggestedRetailPrice = jsonConvert.convert<double>(
      json['minSuggestedRetailPrice']);
  if (minSuggestedRetailPrice != null) {
    priceInfo.minSuggestedRetailPrice = minSuggestedRetailPrice;
  }
  final double? maxProfitPrice = jsonConvert.convert<double>(
      json['maxProfitPrice']);
  if (maxProfitPrice != null) {
    priceInfo.maxProfitPrice = maxProfitPrice;
  }
  final double? minProfitPrice = jsonConvert.convert<double>(
      json['minProfitPrice']);
  if (minProfitPrice != null) {
    priceInfo.minProfitPrice = minProfitPrice;
  }
  final String? salePriceCurrency = jsonConvert.convert<String>(
      json['salePriceCurrency']);
  if (salePriceCurrency != null) {
    priceInfo.salePriceCurrency = salePriceCurrency;
  }
  final bool? isActivityPrice = jsonConvert.convert<bool>(
      json['isActivityPrice']);
  if (isActivityPrice != null) {
    priceInfo.isActivityPrice = isActivityPrice;
  }
  final double? originalMinSalePrice = jsonConvert.convert<double>(
      json['originalMinSalePrice']);
  if (originalMinSalePrice != null) {
    priceInfo.originalMinSalePrice = originalMinSalePrice;
  }
  final double? originalMaxSalePrice = jsonConvert.convert<double>(
      json['originalMaxSalePrice']);
  if (originalMaxSalePrice != null) {
    priceInfo.originalMaxSalePrice = originalMaxSalePrice;
  }
  final String? originalSalePriceCurrency = jsonConvert.convert<String>(
      json['originalSalePriceCurrency']);
  if (originalSalePriceCurrency != null) {
    priceInfo.originalSalePriceCurrency = originalSalePriceCurrency;
  }
  return priceInfo;
}

Map<String, dynamic> $PriceInfoToJson(PriceInfo entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['minSalePrice'] = entity.minSalePrice;
  data['maxSalePrice'] = entity.maxSalePrice;
  data['maxSuggestedRetailPrice'] = entity.maxSuggestedRetailPrice;
  data['minSuggestedRetailPrice'] = entity.minSuggestedRetailPrice;
  data['maxProfitPrice'] = entity.maxProfitPrice;
  data['minProfitPrice'] = entity.minProfitPrice;
  data['salePriceCurrency'] = entity.salePriceCurrency;
  data['isActivityPrice'] = entity.isActivityPrice;
  data['originalMinSalePrice'] = entity.originalMinSalePrice;
  data['originalMaxSalePrice'] = entity.originalMaxSalePrice;
  data['originalSalePriceCurrency'] = entity.originalSalePriceCurrency;
  return data;
}

extension PriceInfoExtension on PriceInfo {
  PriceInfo copyWith({
    double? minSalePrice,
    double? maxSalePrice,
    double? maxSuggestedRetailPrice,
    double? minSuggestedRetailPrice,
    double? maxProfitPrice,
    double? minProfitPrice,
    String? salePriceCurrency,
    bool? isActivityPrice,
    double? originalMinSalePrice,
    double? originalMaxSalePrice,
    String? originalSalePriceCurrency,
  }) {
    return PriceInfo()
      ..minSalePrice = minSalePrice ?? this.minSalePrice
      ..maxSalePrice = maxSalePrice ?? this.maxSalePrice
      ..maxSuggestedRetailPrice = maxSuggestedRetailPrice ??
          this.maxSuggestedRetailPrice
      ..minSuggestedRetailPrice = minSuggestedRetailPrice ??
          this.minSuggestedRetailPrice
      ..maxProfitPrice = maxProfitPrice ?? this.maxProfitPrice
      ..minProfitPrice = minProfitPrice ?? this.minProfitPrice
      ..salePriceCurrency = salePriceCurrency ?? this.salePriceCurrency
      ..isActivityPrice = isActivityPrice ?? this.isActivityPrice
      ..originalMinSalePrice = originalMinSalePrice ?? this.originalMinSalePrice
      ..originalMaxSalePrice = originalMaxSalePrice ?? this.originalMaxSalePrice
      ..originalSalePriceCurrency = originalSalePriceCurrency ??
          this.originalSalePriceCurrency;
  }
}

GoodsPageMeta $GoodsPageMetaFromJson(Map<String, dynamic> json) {
  final GoodsPageMeta goodsPageMeta = GoodsPageMeta();
  final int? pageNum = jsonConvert.convert<int>(json['pageNum']);
  if (pageNum != null) {
    goodsPageMeta.pageNum = pageNum;
  }
  final int? pageSize = jsonConvert.convert<int>(json['pageSize']);
  if (pageSize != null) {
    goodsPageMeta.pageSize = pageSize;
  }
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    goodsPageMeta.total = total;
  }
  final int? pages = jsonConvert.convert<int>(json['pages']);
  if (pages != null) {
    goodsPageMeta.pages = pages;
  }
  return goodsPageMeta;
}

Map<String, dynamic> $GoodsPageMetaToJson(GoodsPageMeta entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['pageNum'] = entity.pageNum;
  data['pageSize'] = entity.pageSize;
  data['total'] = entity.total;
  data['pages'] = entity.pages;
  return data;
}

extension GoodsPageMetaExtension on GoodsPageMeta {
  GoodsPageMeta copyWith({
    int? pageNum,
    int? pageSize,
    int? total,
    int? pages,
  }) {
    return GoodsPageMeta()
      ..pageNum = pageNum ?? this.pageNum
      ..pageSize = pageSize ?? this.pageSize
      ..total = total ?? this.total
      ..pages = pages ?? this.pages;
  }
}